ElsClient Methods

The ElsClient object contains the following methods:

AddEventRecord

The AddEventRecord method adds an event to the ELS.

Syntax

AddEventRecord(RecordXml as String) As String

Parameters

Parameter Required Description

RecordXml

Yes

An XML representation of the record to add to the ELS.

Remarks

The RecordXml parameter of this method can be built using the methods GetEmptyRecordXml and SetRecordXMLAttribute.

Example

The following example builds a record XML and adds it to the ELS.

Copy
AddEventRecord
Sub
    Dim strXml
     
    strXml = ElsClient.GetEmptyRecordXml
     
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "description", "My Description")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "details", "My Details")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "comments", "My Comments")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "eventtimelocal", "3/10/2023 16:03:38.431")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "userflag01", "true")
     
    MsgBox strXml
     
    Dim strDbKey
    strDbKey = ElsClient.AddEventRecord(strXml)
     
    MsgBox strDbKey
End Sub

Back to top

Connect

The Connect method connects the object to a service.

Syntax

Connect(DomainSiteService As String)

Parameters

Parameter Required Description

DomainSiteService

Yes

The [Domain]Site.Service to which to connect. The domain is optional. The service must be a valid one.

Remarks

Returns 0 if successful and a non-zero value if the connection failed.

Example

The following example connects the Client object to the CYGDEMO.<SVC> on domain 5410:

Copy
Connect
Sub ElsConnect()

    'Connect to an ELS
    Dim ElsClient
    Set ElsClient = CreateObject("CxEls.ElsClient")
    ElsClient.Connect("[5410]CYGDEMO.ELS")

End Sub

Back to top

DeleteEventRecord

The DeleteEventRecord method deletes an event from the ELS.

Syntax

DeleteEventRecord(DbKey as String) As Boolean

Parameters

Parameter Required Description

DbKey

Yes

The database key (DbKey) of the record to delete.

Remarks

This method returns false if the record was successfully deleted.

Example

The following example deletes record 0000022430 from the ELS.

Copy
DeleteEventRecord
Sub
    Dim bRet
    bRet = ElsClient.DeleteEventRecord("0000022430")
     
    If Not(bRet) Then
        MsgBox "Event record deleted"
    Else
        MsgBox "Event record not deleted"
    End If
End Sub

Back to top

Disconnect

The Disconnect method disconnects from the connected service.

Syntax

Disconnect() As Integer

Remarks

The Disconnect method returns 0 if successful and a non-zero value if the disconnect failed.

Example

The following example disconnects the Client object from the connected service, and pops a message box if it is unsuccessful:

Copy
Disconnect
Sub Svc.Disconnect()
 
    <SvcClient>.Disconnect()
    MsgBox "Service has disconnected."
    
    If <SvcClient>.Disconnect <> 0 
    Then
        MsgBox "Failed to disconnect."
    End If

End Sub

Back to top

GetConsoleData

The GetConsoleData method returns the console text and display attributes as two 25x80 arrays of unsigned characters.

Syntax

GetConsoleData(ByRef pText, ByRef pAttr) As Integer

Parameters

Parameter Required Description

pText

Yes

A two-dimensional 25x80 array of console text attributes returned by this method.

pAttr

Yes

A two-dimensional 25x80 array of console display attributes returned by this method.

Remarks

This method returns 0 if successful.

Example

The following example writes the console text and display attributes to a CSV file.

Copy
GetConsoleData
Sub
    Dim aryText, aryAttr, nRet
    nRet = <NameofServiceClientObject>.GetConsoleData(aryText, aryAttr)
 
    ' Write text attributes to CSV file
    Dim i, j, strMsg
        For i = 0 To UBound(aryText, 1)
        For j = 0 To UBound(aryText, 2)
            strMsg = strMsg + CStr(aryText(i, j)) + ","
        Next
            strMsg = strMsg + vbCr
    Next
 
    dim fso, file
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set file = fso.OpenTextFile("c:\console_text_attrs.csv", 2, True)
    file.WriteLine(strMsg)
    file.Close 
 
    strMsg = ""
 
    ' Write display attributes to CSV file
        For i = 0 To UBound(aryAttr, 1)
        For j = 0 To UBound(aryAttr, 2)
            strMsg = strMsg + CStr(aryAttr(i, j)) + ","
        Next
            strMsg = strMsg + vbCr
    Next
 
    Set file = fso.OpenTextFile("c:\console_disp_attrs.csv", 2, True)
    file.WriteLine(strMsg)
    file.Close 
 
    MsgBox nRet
End Sub

Back to top

GetEmptyRecordXml

The GetEmptyRecordXml method returns an empty ELS header record.

Syntax

GetEmptyRecordXml() As String

Example

The following example builds a record XML and adds it to the ELS.

Copy
GetEmptyRecordXml
Sub
    Dim strXml
     
    strXml = ElsClient.GetEmptyRecordXml
     
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "description", "My Description")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "details", "My Details")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "comments", "My Comments")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "eventtimelocal", "3/10/2023 16:03:38.431")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "userflag01", "true")
     
    MsgBox strXml
     
    Dim strDbKey
    strDbKey = ElsClient.AddEventRecord(strXml)
     
    MsgBox strDbKey
End Sub

Back to top

GetRecordXMLAttribute

The GetRecordXMLAttribute method returns the value of a specified attribute in the specified record XML.

Syntax

GetRecordXMLAttribute(RecordXml as String, RecordAttribute as String) As String

Parameters

Parameter Required Description

RecordXml

Yes

An XML representation of the record from which to retrieve an attribute.

RecordAttribute

Yes

The attribute to retrieve from the record.  This parameter can be one of the following values:

  • "lock_user" — Lock User
  • "lock_time" — Lock Time
  • "key" — Lock Key
  • "eventtype" — Event Type
  • "source" — Source
  • "category" — Category
  • "description" — Description
  • "details" — Details
  • "comments" — Comments
  • "eventtime" — Event Time
  • "eventtimelocal" — Event Time (local)
  • "userflag01" — User Flag 01
  • "userflag02" — User Flag 02
  • "userflag03" — User Flag 03
  • "userflag04" — User Flag 04
  • "userflag05" — User Flag 05
  • "userflag06" — User Flag 06
  • "userflag07" — User Flag 07
  • "userflag08" — User Flag 08
  • "userflag09" — User Flag 09

Example

The following example displays the value of the "eventtimelocal" attribute for record 0000022430.

Copy
GetRecordXMLAttribute
Sub
    Dim aryDbKeys, aryXml, strAttr
    ReDim aryDbKeys(0)
     
    aryDbKeys(0) = "0000022430"
     
    aryXml = ElsClient.ReadEventRecordsXmlArray(aryDbKeys)
     
    strAttr = ElsClient.GetRecordXMLAttribute(aryXml(0), "eventtimelocal")
     
    MsgBox strAttr
End Sub

Back to top

GetReferences

The GetReferences method refreshes the list of services referenced by the connected service.

Syntax

GetReferences() As Integer

Return Values

This method returns all references for the connected service.

Example

The following example refreshes the connected services:

Copy
GetReferences
Sub GetReferences()
 
    <NameofServiceClientObject>.GetReferences
    MsgBox "Services references retrieved"

End Sub

Back to top

ReadEventComment

The ReadEventComment method returns the comment for a record as an XML formatted string.

Syntax

ReadEventComment(Key As String) As String

Parameters

Parameter Required Description

Key

Yes

The database key (DbKey) - valid Level 2 key

Example

The following example gets the comment from a database key (DbKey).

Copy
ReadEventComment
Sub readComments()
    Dim key
    Dim comment
    key = "0000000034"
     
    comment = ElsClient.ReadEventComment(key)
    MsgBox comment
End Sub

Back to top

ReadEventRecords

The ReadEventRecords method returns the header record fields as an XML string.

Syntax

ReadEventRecords(DbKeys As Array) As String

Parameters

Parameter Required Description

DbKeys

Yes

An array of valid Level 2 database keys (DbKeys).

Example

The following example gets header records from two DbKeys and stores them in an XML document.

Copy
ReadEventRecords
Sub readRecords()
    Dim Keys(1)
    Dim headersXml
     
    Keys(0) = "0000000034"
    Keys(1) = "0000000036"
     
    headersXml = ElsClient.ReadEventRecords(Keys)
     
    'Save header records as XML
    Set xmlDoc = CreateObject("Msxml2.DOMDocument.5.0")
    xmlDoc.loadXML(headersXml)
    xmlDoc.save("C:\HeaderRecords.xml")
End Sub

Back to top

ReadEventRecordsXmlArray

The ReadEventRecords method returns the header record fields as an array of XML strings.

Syntax

ReadEventRecordsXmlArray(DbKeys As Array) As Variant

Parameters

Parameter Required Description

DbKeys

Yes

An array of valid Level 2 database keys (DbKeys).

Example

The following example gets header records from two DbKeys. It then displays the first record in a list box and saves the second record to the hard drive.

Copy
ReadEventRecordsXmlArray
Sub readRecordArray()
    Dim Keys(1)
    Dim arrHeaders
     
    Keys(0) = "0000000034"
    Keys(1) = "0000000036"
     
    arrHeaders = ElsClient.ReadEventRecordsXmlArray(Keys)
     
    'Display the first record
    lboList.AddString(arrHeaders(0))
     
    'Save the second record to the hard drive
    Set xmlDoc = CreateObject("Msxml2.DOMDocument.5.0")
    xmlDoc.loadXML(arrHeaders(1))
    xmlDoc.save("C:\HeaderRecordXml.xml")
End Sub

Back to top

ReadUserFlags

The ReadUserFlags method takes a valid Event Logging Service database key and returns an array of the user flag values.

Syntax

ReadUserFlags(DbKey As String)

Parameters

Parameter Required Description

DbKey

Yes

The database key (DbKey) - valid Level 1 key for the record to update in a string form.

Remarks

Return Value:  An array of the current user flag values. Each Entry in the array represents a single flag. The value of each entry is True if the flag is set, False if the flag is not set. The array index is zero based, so index 0 is UserFlag01 and index 9 is UserFlag10, or one less than the name.

Example

The following example gets the user flag values for DbKey 0000000282 and displays a message box with UserFlag07’s state.

Copy
ReadUserFlags
Dim ElsClient
    Dim arrFlags
     
    'Create the Els Client Object
    ElsClient = CreateObject("CxEls.ElsClient" )
     
    'Connect to the appropriate ELS
    ElsClient.Connect "MYSITE.ELS"
     
    'Read the current user flags on DbKey 0000000282
    arrFlags  = m_ElsClient.ReadUserFlags( "0000000282")
     
    'Now show the current flag value for UserFlag07

If arrFlags(6) Then
    MsgBox "UserFlag07 is Set"
Else
    MsgBox "UserFlag07 is not Set"
End If

Back to top

SetRecordXMLAttribute

The SetRecordXMLAttribute method sets the value of a specified attribute in the specified record XML.

Syntax

SetRecordXMLAttribute(RecordXml as String, RecordAttribute as String, AttributeValue as String) As String

Parameters

Parameter Required Description

RecordXml

Yes

An XML representation of the record for which to set an attribute.

RecordAttribute

Yes

The attribute to set in the record.  This parameter can be one of the following values:

  • "eventtype" — Event Type
  • "source" — Source
  • "category" — Category
  • "description" — Description
  • "details" — Details
  • "comments" — Comments
  • "eventtimelocal" — Event Time (local)
  • "userflag01" — User Flag 01
  • "userflag02" — User Flag 02
  • "userflag03" — User Flag 03
  • "userflag04" — User Flag 04
  • "userflag05" — User Flag 05
  • "userflag06" — User Flag 06
  • "userflag07" — User Flag 07
  • "userflag08" — User Flag 08
  • "userflag09" — User Flag 09

AttributeValue

Yes

The value of the attribute to set.

Remarks

Return Value:  A string containing the new record XML with the updated attribute.

Example

The following example builds a record XML and adds it to the ELS.

Copy
SetRecordXMLAttribute
Sub
    Dim strXml
     
    strXml = ElsClient.GetEmptyRecordXml
     
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "description", "My Description")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "details", "My Details")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "comments", "My Comments")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "eventtimelocal", "3/10/2023 16:03:38.431")
    strXml = ElsClient.SetRecordXMLAttribute(strXml, "userflag01", "true")
     
    MsgBox strXml
     
    Dim strDbKey
    strDbKey = ElsClient.AddEventRecord(strXml)
     
    MsgBox strDbKey
End Sub

Back to top

UpdateEventComment

The UpdateEventComment method adds a comment to a record.

Syntax

UpdateEventComment(DbKey As String, Comment As String)

Parameters

Parameter Required Description

DbKey

Yes

The database key (DbKey) -valid Level 2 key.

Comment

Yes

A string comment to add to the record.

Example

The following example adds a comment to a ELS record.

Copy
UpdateEventComment
Sub updateElsComment()
    Dim key
    Dim myComment
     
    key = "0000000034"
    myComment = "Hello, World!"
     
    ElsClient.UpdateEventComment key, myComment
End Sub

Back to top

UpdateUserFlag

The UpdateUserFlag method takes a valid Event Logging Service database key and will set the specific User Flag on the corresponding record. If setting more than one flag on a given database key (DbKey), using the UpdateUserFlags is more efficient. Set to True to enable, False to disable. Valid Flag values are 1-10

Syntax

UpdateUserFlag(DbKey As String, Flag As Integer, Setting As Boolean)

Parameters

Parameter Required Description

DbKey

Yes

The database key (DbKey) - valid Level 1 key for the record to update in a string form.

Flag

Yes

The flag to change. This is a numeric value of 1 to 10 corresponding to UserFlag01 though UserFlag10.

Setting

Yes

A Boolean value of True to set the user flag or False to clear the user flag.

Remarks

Return Value:  None. An error is generated if the Update to the user flag does not succeed.

Example

The following example clears the first user flag on DbKey 0000000282 and sets the fifth user flag on DbKey 0000000283.

Copy
UpdateUserFlag
Dim ElsClient
 
'Create the Els Client Object
 
ElsClient = CreateObject("CxEls.ElsClient" )
 
'Connect to the appropriate ELS
ElsClient.Connect "MYSITE.ELS"
 
'Clear UserFlag01 on DbKey 0000000282
m_ElsClient.UpdateUserFlag( "0000000282", 1, False)
...
...
'Set UserFlag05 0000000283
m_ElsClient.UpdateUserFlag( "0000000283", 1, True)

Back to top

UpdateUserFlags

The UpdateUserFlags method takes a valid Event Logging Service database key and will set the specific User Flag on the corresponding record. If setting more than one flag on a given database key (DbKey), using the UpdateUserFlags is more efficient. True means set the flag, False means clear the flag, Empty or Null means leave existing value.

Syntax

UpdateUserFlags(DbKey As String, ArrFlags)

Parameters

Parameter Required Description

DbKey

Yes

The database key (DbKey) - valid Level 1 key for the record to update in a string form.

arrFlags

Yes

An array of the flags to change. Each Entry in the array maybe represents a single flag. The value of each entry is True to set the flag, False to clear the Flag or Empty or Null to retain the current value of the flag. The array index is zero based, so index 0 is UserFlag01 and index 9 is UserFlag10.

Remarks

Return Value:  None. An error is generated if the Update to the user flags does not succeed.

Example

The following example clears UserFlag01 and sets UserFlag05 on DbKey 0000000282. Then, it clears all the flags on DbKey 0000000283 except for UserFlag07.

Copy
UpdateUserFlags
Dim ElsClient
Dim arrFlags
Dim iIndex
 
'Create the Els Client Object
 
ElsClient = CreateObject("CxEls.ElsClient" )
 
'Connect to the appropriate ELS
ElsClient.Connect "MYSITE.ELS"
 
'allocate the array, Redim is the upperbound based so subtract 1
'from the number of flags.
 
Redim arrFlags(ElsClient.UserFlagCount - 1)
 
'Clear UserFlag01, set UserFlag05, and leave all the rest alone
arrFlags(0) = False
arrFlags(4) = True
 
'Update the flags on dbkey 0000000282
m_ElsClient.UpdateUserFlags( "0000000282, arrFlags)
...
...
'Now Clear all the flags on 0000000283 except UserFlag07
'Clear all the flags
For iIndex = LBound(arrFlags) to UBound(arrFlags )
arrFlags(iIndex) = False
Next
 
'Retain the value for UserFlag07
arrFlags(6) = Empty
 
'Now update the flags
m_ElsClient.UpdateUserFlag( "0000000283", arrFlags)

Back to top